package net.dntuan.simple.web.servlet;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * Test the method response.sendRedirect(). The statements after the call of this method are still executed
 * 
 * @author tuan.dang
 *
 * <br>$LastChangedRevision: 37 $
 * <br>$LastChangedDate: 2014-04-07 16:55:59 +0000 (Mon, 07 Apr 2014) $ 
 */
public class WelcomeServlet implements Servlet {
	private static final Logger LOGGER = Logger.getLogger(WelcomeServlet.class.getName());

	@Override
	public void init(ServletConfig config) throws ServletException {
	}

	@Override
	public ServletConfig getServletConfig() {
		return null;
	}

	@Override
	public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
		HttpServletResponse httpResponse = (HttpServletResponse) res;
		httpResponse.sendRedirect("../index.html");
		LOGGER.info("after sending redirect, the next code is STILL run");
	}

	@Override
	public String getServletInfo() {
		return null;
	}

	@Override
	public void destroy() {
	}

}
